package com.zhiren.bookfood.controller;

/**
 * 
 */
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author MARCO.PAN
 *
 */
public abstract class BaseController extends ActionSupport {

	protected void setSessionVal(String key, Object val){
		getRequest().getSession().putValue(key, val);
	}
	
	protected Object getSessionVal(String key){
		return getRequest().getSession().getValue(key);
	}
	
	protected void removeSessionVal(String... keys){
		for(String key : keys){
			getRequest().getSession().removeAttribute(key);
		}
	}
	
	protected HttpServletRequest getRequest(){
		return ServletActionContext.getRequest();
	}
	
	protected void writeRes(String info){
		HttpServletResponse res = ServletActionContext.getResponse();
		try {
			res.setCharacterEncoding("utf-8");
			res.getWriter().write(info);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
